001 package jgb.examples.eventhandlers; 002 003 004 import jgb.builder.TagHandler; 005 006 import javax.swing.*; 007 import java.util.EventObject; 008 import java.util.Map; 009 010 /** 011 * @author Francois Beausoleil, <a href="mailto:fbos@users.sourceforge.net">fbos@users.sourceforge.net</a> 012 */ 013 public class ListAddHandler { 014 private String modelId; 015 private String textFieldId; 016 017 public ListAddHandler(String modelId, String textFieldId) { 018 this.modelId = modelId; 019 this.textFieldId = textFieldId; 020 } 021 022 public void handleEvent(Map context, EventObject eventObject) { 023 Map objectsMap = (Map)context.get(TagHandler.OBJECTS_MAP_KEY); 024 DefaultListModel model = (DefaultListModel)objectsMap.get(modelId); 025 JTextField field = (JTextField)objectsMap.get(textFieldId); 026 027 model.addElement(field.getText()); 028 field.setText(""); 029 } 030 }